# -*- coding:utf-8 -*-
from pymongo import MongoClient
from config import config


def do_it_one(item):
    print item['title']


def main():
    mongodb_client = MongoClient(config.mongodb_host, config.mongodb_port)
    mongodb_db = mongodb_client[config.mongodb_db]
    mongodb_db_book_info = mongodb_db[config.mongodb_table_book_info]

    limit = 1000
    offset = 0
    while True:
        print offset
        items = mongodb_db_book_info.find({

        }).sort({"vote_num": -1}).skip(offset).limit(limit)
        count = 0
        for item in items:
            do_it_one(item)
            count += 1
        if count == 0:
            break
        offset += limit


if __name__ == '__main__':
    main()
